<?php
/*
 * code to process a timesheet when saved.  data sent from mytimesheet.php in a serialised form
*/
// Create connection
include("../inc_files/utils/dbconnection.php");

$stmt = $mysqli->prepare("UPDATE timesheet_lines SET
		SunHours=?, MonHours=?, TueHours=?,
		WedHours=?, ThurHours=?, FriHours=?,
		SatHours=? WHERE TimesheetLineID = ?");

$stmt->bind_param('dddddddi', $a, $b, $c, $d, $e, $f, $g, $key);
//split each week's data into an array
$rowData= explode("Sun", substr($_POST["formdata"], 3));

foreach ($rowData as $rowValue){
	if (strlen($rowValue) > 0){
		//get the ID of the record
		$key = substr($rowValue, 1,strpos($rowValue, "~")-1);

		//get the field=value pairs
		$columnData = explode("|",$rowValue);

		$aa = explode("~",$columnData[0]);
		$a = $aa[1];

		$ba = explode("~",$columnData[1]);
		$b = $ba[1];

		$ca = explode("~",$columnData[2]);
		$c = $ca[1];

		$da = explode("~",$columnData[3]);
		$d = $da[1];

		$ea = explode("~",$columnData[4]);
		$e = $ea[1];

		$fa = explode("~",$columnData[5]);
		$f = $fa[1];

		$ga = explode("~",$columnData[6]);
		$g = $ga[1];

		$stmt->execute();
	}

}

//tidy up database connection
$stmt->close();
$mysqli->close();
?>